﻿using Autofac;
using MahApps.Metro.Controls;
using PLC.Interface.Groups;
using PLCWpfTest.Common;
using PLCWpfTest.Common.Extensions;
using PLCWpfTest.ViewModels;
using System;
using System.Windows;
using YWM;

namespace PLCWpfTest.Views
{
    /// <summary>
    /// GroupManagementWindow.xaml 的交互逻辑
    /// </summary>
    public partial class GroupConfigWindow : MetroWindow
    {
        private readonly GroupConfigViewModel _groupConfigViewModel;
        public GroupConfigWindow(GroupConfigViewModel groupConfigViewModel)
        {
            InitializeComponent();
            DataContext = _groupConfigViewModel = groupConfigViewModel;
        }

        private async void AddButton_Click(object sender, RoutedEventArgs e)
        {
            GroupOperationWindow groupOperationWindow = YApp.Resolve<GroupOperationWindow>(new NamedParameter(Constant.DTO_GROUP, null));
            if (groupOperationWindow.ShowDialog() == true)
            {
                await _groupConfigViewModel.SearchAsync();
            }
        }

        private async void EditButton_Click(object sender, RoutedEventArgs e)
        {
            if (GroupDataGrid.SelectedValue == null)
            {
                this.ShowWarning("请选择一行编辑");
                return;
            }
            GroupOperationWindow groupOperationWindow = YApp.Resolve<GroupOperationWindow>(new NamedParameter(Constant.DTO_GROUP, (GroupDto)GroupDataGrid.SelectedValue));
            if (groupOperationWindow.ShowDialog() == true)
            {
                await _groupConfigViewModel.SearchAsync();
            }
        }
    }
}
